﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GameFramework;
using GameFramework.Event;
using UnityGameFramework.Runtime;
using GameFramework.Procedure;
using ProcedureOwner = GameFramework.Fsm.IFsm<GameFramework.Procedure.IProcedureManager>;

public class Demo7_ProcedureLaunch : ProcedureBase
{
    protected override void OnEnter(ProcedureOwner procedureOwner)
    {
        base.OnEnter(procedureOwner);
        EventComponent Event = GameEntry.GetComponent<EventComponent>();
        Event.Subscribe(WebRequestSuccessEventArgs.EventId, OnWebRequestSuccess);
        Event.Subscribe(WebRequestFailureEventArgs.EventId, OnWebRequestFailure);

        WebRequestComponent WebRequest = GameEntry.GetComponent<WebRequestComponent>();
        string url = "http://gameframework.cn/starforce/version.txt";
        WebRequest.AddWebRequest(url, this);
    }

    private void OnWebRequestSuccess(object sender, GameEventArgs e)
    {
        WebRequestSuccessEventArgs ne = (WebRequestSuccessEventArgs)e;
        string responseJson = Utility.Converter.GetString(ne.GetWebResponseBytes());
        Log.Debug("responseJson : " + responseJson);
        //Log.Info("str : " + responseJson.InternalApplicationVersion);
    }

    private void OnWebRequestFailure(object sender, GameEventArgs e)
    {
        Log.Debug("请求失败！！");
    }

    // Use this for initialization
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {

    }
}
